<?php
declare(strict_types=1);
namespace cms\tencent\service;

use cms\tencent\model\HandleModel;
use Hyperf\Di\Annotation\Inject;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;

class HandleService extends CommonService
{
    /**
     * @Inject()
     * @var HandleModel
     */
    public HandleModel $model;

    /**
     * @Inject()
     * @var AppService
     */
    public AppService $appService;

    public function action(HandleModel $handle)
    {
        $app = $this->appService->initApp($handle->app);
        $httpProfile = new HttpProfile();
        $httpProfile->setEndpoint($handle->config->request_url);
        $clientProfile = new ClientProfile();
        $clientProfile->setHttpProfile($httpProfile);
        $client_class = $handle->config->client_class;
        $client = new $client_class($app, '', $clientProfile);
        $request_class = $handle->config->request_class;
        $request = new $request_class();
        $request->fromJsonString(json_encode($handle->setting['param']));
        $request_action = $handle->config->request_action;
        $response = $client->$request_action($request);
        var_dump($response);
    }
}